package cn.qiyu5522.tk_ems.service.impl;

import cn.qiyu5522.tk_ems.entity.User;
import cn.qiyu5522.tk_ems.entity.dto.UserDTO;
import cn.qiyu5522.tk_ems.mapper.UserMapper;
import cn.qiyu5522.tk_ems.result.R;
import cn.qiyu5522.tk_ems.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Tonkey
 * @since 2023-02-01
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private ObjectMapper objectMapper;

    @Override
    public R saveMore(List<UserDTO> userDTOS) {
        List<User> users = objectMapper.convertValue(userDTOS, new TypeReference<List<User>>() {
        });
        Integer integer = baseMapper.insertBatchSomeColumn(users);
        return integer>0 ? R.ok().message("添加成功"):R.ok().message("添加失败");
    }
}
